// admin业务逻辑

const md5 = require('md5');

const jwt = require('jsonwebtoken')

const {loginDao} = require('../dao/adminDao')

module.exports.loginService = async function(loginInfo) {

    // loginInfo.loginPwd = md5(loginInfo.loginPwd)
    console.log(loginInfo , 'loginInfo')
    let data = await loginDao(loginInfo)
    console.log('data' , data)
    if (data && data.dataValues) {

        data = {
            id:data.dataValues.id,
            loginId:data.dataValues.loginId,
            name:data.dataValues.name,
        }
        let loginPeriod = 1
        if (data && data.remember) {
            loginPeriod = data.remember
        }
        const token = jwt.sign(data,md5(process.env.DB_SECRET), {expiresIn :60 * 60 * 24 * loginPeriod})
        console.log(token ,'token')
        return {token , data}
    }
    return {data}
}